package com.atguigu.yygh.user.controller.user;


import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.result.R;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.utils.JwtHelper;
import com.atguigu.yygh.vo.user.LoginVo;
import com.atguigu.yygh.vo.user.UserAuthVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-04-22
 */
@RestController
@RequestMapping("/user/userinfo")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;



    //获取当前用户的基本信息
    @GetMapping("/info")
    public R getUserInfo(@RequestHeader String token){
        Long userId = JwtHelper.getUserId(token);
        UserInfo userInfo1=userInfoService.selectById(userId);
        return R.ok().data("userInfo",userInfo1);
    }


    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo){
       Map<String,Object> map= userInfoService.login(loginVo);
       return R.ok().data(map);
    }



    //保存实名认证信息
    @PutMapping("/save")
    public R saveUserInfo(UserAuthVo userAuthVo,@RequestHeader String token){
        Long userId = JwtHelper.getUserId(token);
        userInfoService.updateUserInfo(userId,userAuthVo);
        return R.ok();
    }
}

